package com.cpj.bsyyzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.Bed;
import com.cpj.bsyyzx.entity.BedRecord;
import com.cpj.bsyyzx.mapper.BedMapper;
import com.cpj.bsyyzx.service.IBedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.omg.PortableServer.POA;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@Service
public class BedServiceImpl extends ServiceImpl<BedMapper, Bed> implements IBedService {

    @Override
    public Page pageList(Page page, Bed bed) {
        if (page == null){
            page=new Page();
        }
        QueryWrapper wrapper =new QueryWrapper();
        if (bed !=null && !StringUtils.isEmpty((bed.getBedNum()))){
            wrapper.like("bed_num",bed.getBedNum());
        }
        page.setSize(16);
        return super.page(page,wrapper);
    }

    @Override
    public Page selectByFloor(Page page, Integer floor) {
        if(page ==null){
            page =new Page();
        }
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("floor",floor);
        return super.page(page,wrapper);
    }

    @Override
    public Page selectFind(Page page, String ConditionValue) {
        if (page ==null){
            page=new Page();
        }
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.like("bed_num",ConditionValue);
        return super.page(page,wrapper);
    }

    @Override
    public Page selectFindNums(List<BedRecord> list) {
        Page page=new Page();
        page.setSize(15);
        QueryWrapper wrapper=new QueryWrapper();
        for (BedRecord bedRecord : list) {
            wrapper.in("bed_num",bedRecord.getBedInformation());
        }
        return super.page(page,wrapper);
    }


    @Override
    public HashMap AllCount() {
        HashMap map=new HashMap();
        Integer AllCount=super.count();

        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("status",0);
        Integer FreeCount=super.count(wrapper);

        QueryWrapper wrapper1=new QueryWrapper();
        wrapper1.ne("status",0);
        Integer ExCount=super.count(wrapper1);

        QueryWrapper wrapper2=new QueryWrapper();
        wrapper2.eq("status",2);
        Integer leftCount=super.count(wrapper2);

        QueryWrapper wrapper3=new QueryWrapper();
        wrapper3.eq("status",3);
        Integer StayBackCount=super.count(wrapper3);

        map.put("AllCount",AllCount);
        map.put("FreeCount",FreeCount);
        map.put("ExCount",ExCount);
        map.put("leftCount",leftCount);
        map.put("StayBackCount",StayBackCount);
        return map;
    }
}
